package org.orbis.spikezolt;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.primitive.Rectangle;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;

import android.R.string;
import android.util.Log;

public class Block {
	public Sprite spr; // Block
	private Body body; // Body
	private SpikeZoltActivity sa;
	
	String type;

	Block(SpikeZoltActivity sa, int x, int y, int width, int height, String type) {
		this.sa = sa;
		this.type = type;
		TextureRegion r;

		if (type.equals("rBlock")) {
			r = sa.texManager.TR_blockRed;
		} else if (type.equals("bBlock")) {
			r = sa.texManager.TR_blockBlue;
		} else if (type.equals("pBlock")) {
			r = sa.texManager.TR_blockPurple;
		} else {
			r = sa.texManager.TR_blockRed;
		}

		spr = new Sprite(x, y, r);
		// STATIC BODY
		final Shape boxShape = new Rectangle(x, y, width,
				height);
		final FixtureDef wallFixtureDef = PhysicsFactory
				.createFixtureDef(0, 0.5f, 0.5f);
		wallFixtureDef.restitution = 0.0f;
		wallFixtureDef.friction = sa.WALL_FRICTION;
		body = PhysicsFactory.createBoxBody(
				sa.mPhysicsWorld, boxShape,
				BodyType.StaticBody, wallFixtureDef);
		body.setUserData("wall");
		////////////////
		
		sa.scene.attachChild(spr);		

	}
	
	public void destroy(boolean effects){		
		//if(sa.scene.detachChild(spr));
		spr.detachSelf();
		body.getFixtureList().removeAll(body.getFixtureList());
		sa.mPhysicsWorld.destroyBody(body);
	}
}
